﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UM_SERVER.User
{
    class UserManager : Manager
    {
        /// <summary>
        ///     通过指定KEY，得到用户对象
        /// </summary>
        /// <param name="Key" type="string">
        ///     <para>
        ///         用户KEY
        ///     </para>
        /// </param>
        /// <returns>
        ///     返回对应用户
        /// </returns>
        public User GetUser(String Key)
        {
            IMetaData user = this.GetMemberByKey(Key);
            if(user != null)
            {
                return (User) user;
            }
            return null;
        }

        /// <summary>
        ///    覆盖已经存在的登陆用户
        /// </summary>
        /// <param name="user">当前新用户</param>
        /// <returns>返回 false, 则表示覆盖失败</returns>
        public bool CoverLoginUser(IMetaData user)
        {
            for (int i = 0; i < Collection.Count; i++)
            {
                if (Collection[i].Key == user.Key)
                {
                    Collection[i] = user;
                    return true;
                }
            }
            return false;
        }
    }
}
